#include <rtthread.h>
#include <rtdevice.h>
#include "transparent_protocol.h"
#include "gb_15322_pal.h"

int gb_15322_response(unsigned int addr, unsigned char ctl, 
                      void *data, int len, 
                      char **encode_data, int *encode_len)
{
    s_gb_15322 page = {0};

    page.precode = PRO_HEAD;
    page.version = GB18322_VERSION;
    page.addr = addr;
    page.ctl = ctl;
    page.datalen = len;
    page.data = data;
    page.tailcode = PRO_TAIL;

    *encode_data = rt_malloc(len + sizeof(s_gb_15322));
    if (NULL == *encode_data)
    {
        return 1;
    }

    gb_15322_encode((void *)&page, *encode_data, encode_len);

    return 0;
}